<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="<c:url value='/js/plug/area/load_area.js'/>"></script>


<div id="cc_buyers" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'销售明细',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
			    <td class="screen-n"><span>采购商名称</span></td>
				<td class="screen-n">
					<input type="text" id="s_buyerChsName" class="screen-input" style="width:200px" onkeydown="pms.kd13('initSaleDetail')">
				</td>
				<td class="screen-n"><span>药品名称</span></td>
				<td class="screen-n">
					<input type="text" id="s_productName" class="screen-input" style="width:200px" onkeydown="pms.kd13('initSaleDetail')">
				</td>
				<td class="screen-n"><span>品牌</span></td>
				<td class="screen-n">
					<input type="text" id="s_brand" class="screen-input" style="width:90px" onkeydown="pms.kd13('initSaleDetail')">
				</td>
				<td class="screen-n"><span>销售地区</span></td>
				<td class="screen-n">
						<div id="loc" >
     		                  <select name="province" id="province" style="width:80px;">
     		                     <option value="0">选择省</option>
     		                  </select>   
     		                  <select name="city" id="city" style="width:80px;">
     		                     <option value="0">选择市</option>
     		                  </select>   
     		                  <select name="district" id="district" style="width:80px;">
     		                     <option value="0">选择地区</option>
     		                  </select>
     	                  </div>
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initSaleDetail()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
				    <input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>  
<script>
var toolbar = [];
var saleDetailTable;
$(function(){
	initSaleDetail();
});
function getParams(){
	var queryParamss = {
			"buyerChsName":$('#s_buyerChsName').val(),
			"productName":$('#s_productName').val(), 
			"brand":$('#s_brand').val(),
			"areaCode":$('#loc').getLocation('all').code
	    };
    return queryParamss;
}
function initSaleDetail(){
	saleDetailTable = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
		columns:[[
				   {field:'ck',checkbox:true},
	               {field:'areaName',title:'销售地区',align:'center'},
	               {field:'buyerChsName',title:'采购商名称',align:'center',formatter:function(value,row){
						if(row.buyerId != '' && row.buyerId != null){
							return '<a href="javascript:void(0);" onClick="openBuyerUpdateWindow(\''+row.buyerId+'\')" title="查看采购商详情">'+value+'</a>';
						}else{
							return value;
						}  
				   }},
	               {field:'productName',title:'药品名称',align:'center',formatter:function(value,row){
						if(row.productCode != '' && row.productCode != null){
							return '<a href="javascript:void(0);" onClick="openProductAddOrSaveWindow(\''+row.productCode+'\')" title="查看药品详情">'+value+'</a>';
						}else{
							return value;
						}  
				   }},
	               {field:'confirmAmount',title:'数量',align:'center',sortable:true},
	               {field:'confirmMoney',title:'金额',align:'center',sortable:true},
	               {field:'createDate',title:'销售日期',align:'center',sortable:true},
	               {field:'producingName',title:'生产厂家',align:'center'},
	               {field:'brand',title:'品牌',align:'center',formatter:function(value,row){
						if(row.brandId != '' && row.brandId != null){
							return '<a href="javascript:void(0);" onClick="openBrandUpdateWindow(\''+row.brandId+'\')" title="查看品牌详情">'+value+'</a>';
						}else{
							return value;
						} 
				   }}
		          ]],
		    url:'<c:url value="/charge/searchPageSaleDetail.do"/>',  
		    pagination:true,
		    pageSize:10,
		    fitColumns:false,
		    singleSelect:false,
		    queryParams:getParams(),
			completeCallback:function(data){
			},
			onLoadSuccess : function(data) {
				var panel = $(this).datagrid('getPanel');
				var tr = panel.find('div.datagrid-body tr');
				tr.each(function() {
					var td = $(this).children('td[field="areaName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
				tr.each(function() {
					var td = $(this).children('td[field="buyerChsName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
				tr.each(function() {
					var td = $(this).children('td[field="productName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
			}
	}); 
}

$("#loc").LocationSelect({
	data:"<c:url value='/js/plug/area/areas.json' />"
});
function openBuyerUpdateWindow(code){
	var params = {"code":code,
			      "onViewFlag":true};
	$.pmsDialog({
		id:"w_buyer_detail",
		title:'采购商详情',
		isIf:'true',
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/customer/buyer/buyer_detail.jsp"/>',
		width:850
	}); 
}
function openProductAddOrSaveWindow(productCode){
	var params = {"productCode":productCode,
		          "onViewFlag":true};
	$.pmsDialog({
		id:"w_product_save_add",
		title:'商品详情',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_save_update_s.jsp"/>',
		width:1100,
		params:params,
		isIf:'true'
		
	});
}
function openBrandUpdateWindow(code){
	var params = {"code":code,
		          "onViewFlag":true};
	$.pmsDialog({
		id:"w_brand_detail",
		title:'品牌详情',
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/brand/brand_detail.jsp"/>',
		width:600,
		height:430
	}); 
}

//导出
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/charge/searchPageSaleDetailExcel.do"/>',getParams());
} 	
</script>
